﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Sausage.Common;
using Sausage.Web.DataModel;
using Sausage.Web.Domain;
using Sausage.Web.Models;
using Sausage.Web.Code;

namespace Sausage.Web.Controllers
{
    /// <summary>
    /// 文件上传控制器
    /// </summary>
    public class FileUploadController : Controller
    {
        /// <summary>
        /// 上传临时文件
        /// </summary>
        /// <returns>操作结果。</returns>
        /// <remarks></remarks>
        [HttpPost]
        [JsonHandleError]
        [PermissionCheckAttribute("*")]
        public ActionResult UploadTempFile(UploadFileModel data)
        {
            Guid fileID = Guid.Empty;
            bool success = FileUploadHelper.UploadFile(data, this.Request.Files, out fileID);
            data.FileID = fileID;

            return Json
            (
                new JsonResultViewModel
                {
                    success = success,
                    message = success ? "文件上传成功！" : "文件上传失败！",
                    data = data
                },
                JsonRequestBehavior.AllowGet
            );
        }
    }
}
